package com.kuangstudy.common.demo6;

/**
 * ClassName: Demo5
 * date: 2021/07/14 16:55:12
 *StringBuffer和StringBuilder的使用
 * 和String的区别：效率比String高 比String节省内存
 * 单线程用StringBuilder
 * 多线程用StringBuffer
 * @author zlk
 */
public class Demo5 {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder();
        //append();追加
        sb.append("java世界第一");
        System.out.println(sb);
        sb.append("java真香");
        System.out.println(sb);
        //insert();添加
        sb.insert(0,"我在最前面");
        System.out.println(sb);
        //replace
        sb.replace(0,5,"hello");
        System.out.println(sb);
        //delete
        sb.delete(0,5);
        System.out.println(sb);
        //reverse 反转
        sb.reverse();
        System.out.println(sb);
        //清空
        sb.delete(0,sb.length());
        System.out.println(sb.length());
    }
}
